package com.projet.entity;

import java.util.ArrayList;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

public abstract class Entity implements IEntity{

	String id;
	 
    Vector2f position;
    float scale;
    float rotation;
 
    RenderComponent renderComponent = null;
 
    ArrayList<IComponent> components = null;

	
	
	public Entity() {
		id="defaut";
		position = new Vector2f();
		position.set(20f, 20f);
		scale=0f;
		rotation=0f;
		components= new ArrayList<IComponent>();
	}
	
	
	

	
	
	@Override
	public void AddComponent(IComponent component) {
		components.add(component);
		
	}

	@Override
	public int compareTo(IEntity o) {
		return this.getId().compareToIgnoreCase(o.getId());
	}

	@Override
	public IComponent getComponent(String id) {
		
		for (IComponent c : this.components)
		{
			if (c.getId()==id)
			{
				return c;
			}
		}
		return null;
		
	}

	@Override
	public String getId() {
		return this.id;
	}

	@Override
	public Vector2f getPosition() {
		return this.position;
	}

	@Override
	public float getRotation() {
		return this.rotation;
	}

	@Override
	public float getScale() {
		return this.scale;
	}

	

	@Override
	public void setPosition(Vector2f position) {
		this.position= position;
		
	}

	@Override
	public void setRotation(float rotate) {
		this.rotation=rotate;
		
	}

	@Override
	public void setScale(float scale) {
		this.scale= scale;
		
	}

	@Override
	public void update(GameContainer gc, StateBasedGame sb, int delta) {
		for (IComponent c : this.components)
		{
			c.update(gc, sb, delta);
		}
		this.renderComponent.update(gc, sb, delta);
		
	}
	
	@Override
	public void render(GameContainer gc, StateBasedGame sb, Graphics gr) {
		this.renderComponent.render(gc, sb, gr);
		
	}





	/**
	 * @return the renderComponent
	 */
	public RenderComponent getRenderComponent() {
		return renderComponent;
	}





	/**
	 * @param renderComponent the renderComponent to set
	 */
	public void setRenderComponent(RenderComponent renderComponent) {
		this.renderComponent = renderComponent;
	}





	/**
	 * @return the components
	 */
	public ArrayList<IComponent> getComponents() {
		return components;
	}





	/**
	 * @param components the components to set
	 */
	public void setComponents(ArrayList<IComponent> components) {
		this.components = components;
	}
	
	

}
